package com.cskaoyan.bean;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.*;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

/**
 * @author stone
 * @date 2022/08/02 10:56
 */
public class LifecycleBean implements BeanNameAware, BeanFactoryAware, ApplicationContextAware,
        InitializingBean, DisposableBean
{

    String username;

    String beanName;
    BeanFactory beanFactory;
    ApplicationContext applicationContext;

    public void setUsername(String username) {
        System.out.println("设置属性值");
        this.username = username;
    }

    @Override
    public void setBeanName(String beanName) {
        System.out.println("setBeanName");
        this.beanName = beanName;
    }

    @Override
    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
        System.out.println("setBeanFactory");
        this.beanFactory = beanFactory;
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        System.out.println("setApplicationContext");
        this.applicationContext = applicationContext;
    }

    // 自己指定初始化方法 → 方法名任意写
    public void init() {
        System.out.println("自定义的init初始化");
    }

    // 实现接口里的方法
    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("afterPropertiesSet方法");
    }

    public void mydestroy() {
        System.out.println("自定义destroy");
    }

    @Override
    public void destroy() throws Exception {
        System.out.println("DisposableBean接口的destroy");
    }
}
